package com.xisoft.base.core.cinfig;

import com.xisoft.base.core.filter.MyAppFilter;
import com.xisoft.base.core.listener.MyAppListener;
import com.xisoft.base.core.servlet.MyAppServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Configuration
public class MyServiceConfig {
    @Bean
    public ServletListenerRegistrationBean<MyAppListener> regMyListener() {

        System.err.println("MyServiceConfig...注册...ServletListenerRegistrationBean...");

        ServletListenerRegistrationBean<MyAppListener> registrationBean =
                new ServletListenerRegistrationBean<MyAppListener>(new MyAppListener());
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean<MyAppFilter> regMyFilter() {
        System.err.println("MyServiceConfig...注册...FilterRegistrationBean...");

        FilterRegistrationBean<MyAppFilter> registrationBean = new FilterRegistrationBean<MyAppFilter>();
        registrationBean.setFilter(new MyAppFilter());
        // 請求地址
        registrationBean.setUrlPatterns(Arrays.asList("/FoodServlet", "/food"));

        return registrationBean;
    }

    @Bean
    public ServletRegistrationBean<MyAppServlet> regMyServlet() {
        System.err.println("MyServiceConfig...注册...ServletRegistrationBean...");

        ServletRegistrationBean<MyAppServlet> servletRegistrationBean =
                new ServletRegistrationBean<MyAppServlet>(new MyAppServlet(), "/MyServlet");

        return servletRegistrationBean;
    }

}
